<template>
	<div class="scene-page">
		<!-- gis外场景地图 --> 


		<!-- unity3d模型内场景 -->
		<unity3d ref="_su3d" @back="onU3dOut"></unity3d>
	</div>

</template>

<script setup>
	import {
		computed,
		watch,
		ref,
		toRefs,
		onBeforeUnmount,
		onUnmounted,
		onMounted,
		nextTick,
	} from "vue";

	import {
		onBeforeRouteUpdate,
		useRoute,
		useRouter
	} from "vue-router";
	import {
		ElMessage,
		ElMessageBox
	} from "element-plus";
	import {
		useStore
	} from "vuex";
 
	import unity3d from "./Unity3d.vue";
	import {
		hDo
	} from "@/api/proj.js";

	const _useRoute = useRoute();
	const store = useStore();

	const {
		showGis,
		jdtk,
		sceneDat,
		usedMods
	} = toRefs(store.state);


	const hMsg = (m, dat) => {
		ElMessageBox.confirm(
			m + JSON.stringify(dat),
			'异常', {
				confirmButtonText: '确定',
				type: 'warning',
				center: true,
			}
		);
	}

	const _sgis = ref(null),
		_su3d = ref(null);

	const hCallIn = (h, d) => {
		if (showGis.value) {
			_sgis.value?.hCallIn(h, d);
			return;
		}
		_su3d.value?.hCallIn(h, d);
	};


	const onGisOut = (d) => {

	}

	const onU3dOut = (d) => {

	}
	const hLoad = (isgis) => {
		showGis.value = isgis;

	}
	const hRefPage = () => {
		let arg = _useRoute.query;
		let sn = arg.scene || null /*预览*/ ,
			v = arg.id || null /*id==0新增，id>0编辑*/ ;
		let k = 'id';
		if (sn) {
			k = 'url';
			v = `'${sn}'`;
		}
		hDo.sceneGet(k, v, (s) => {
			_datScene = s[0] ? s[0] : s;
			sceneDat.value = _datScene;
			hLoad(arg.isgis == 1 || _datScene.def3d == 0 || arg.is3d == 'false');
		});
	}

	//参数设置	 
	const props = defineProps({
		datMods: {
			type: Array
		},
	});
	defineExpose({
		hCallIn,
	});

	onBeforeUnmount(() => {
		//scene.instance?.hFree();
		//	console.log("退出前");
	});
	onUnmounted(() => {
		//scene.instance = null;
	});

	onMounted(() => nextTick(() => {

		hRefPage();
	}));
</script>

<style scoped lang="scss">


</style>